'''
Created on Oct 11, 2012

@author: daeheehan
'''
from pprint import pprint
from github3 import login, GitHub
from getpass import getpass, getuser

import datetime
import dateutil.parser
import time
import sys

# Github User information
GITHUB_USER_ID = "booknara"
GITHUB_USER_ID_1 = "booknaratest"
GITHUB_USER_ID_2 = "jangho87"
GITHUB_USER_ID_3 = 'luispigu'
GITHUB_USER_ID_4 = 'skswhwo'

GITHUB_USER_PW = "qwer1234"
GITHUB_USER_PW_1 = "wasd1234"

if __name__ == '__main__':
    pass

gh = login(GITHUB_USER_ID, password=GITHUB_USER_PW)
print gh.ratelimit_remaining, 'request remaining'

# Github oh-my-zsh Repository information
GITHUB_USER_NAME = 'robbyrussell'
GITHUB_REPOSITORY_NAME = 'oh-my-zsh'

# oh-my-zsh collaborators information file
COLLABORATORS_FILE = 'oh_my_zsh_collaborators.txt'

# oh-my-zsh contributors information file
CONTRIBUTORS_FILE = 'oh_my_zsh_contributors.txt'

# oh-my-zsh collaborator followers information file
COLLABORATORS_FOLLOWER_FILE = 'oh_my_zsh_collaborators_follower.txt'

# oh-my-zsh contributors following collaborators information file
CONTRIBUTORS_FOLLOWER_COLLABORATORS_FILE = 'oh_my_zsh_contributors_follower_collaborators.txt'

project_collaborators = []
project_contributors = []
collaborators_follower = {}

contributors_follower_collaboratos = {}

try:
    # Github project collaborator list from files
    f_collaborators = open(COLLABORATORS_FILE, 'r')
    
    for line in f_collaborators:
        if not line.strip():
            continue
        # We got something, save it
        else:
            tuple_list = line.split(',')
            
            login = tuple_list[1].strip()
            start_offset = login.find(':')
            user_login = login[start_offset+1:].strip()
#            print user_login
            project_collaborators.append(user_login)

    f_collaborators.close()

    # Github project contributors list from files
    f_contributors = open(CONTRIBUTORS_FILE, 'r')
    
    for line in f_contributors:
        if not line.strip():
            continue
        # We got something, save it
        else:
            tuple_list = line.split(',')
            
            login = tuple_list[1].strip()
            start_offset = login.find(':')
            user_login = login[start_offset+1:].strip()
#            print user_login
            project_contributors.append(user_login)

    f_contributors.close()

    # project_collaborators list
    # project_contributors list
    b_follower = 0
    for contributor in project_contributors:
        print contributor
#        contributor = 'drake01'
        
        for collaborator in project_collaborators:
            print collaborator
            
            for item in gh.iter_followers(collaborator):
                if contributor == item.login:
                    print 'the same value'
                    continue
                elif item.login == contributor:
                    print 'found'
                    b_follower = 1
        break
#            contributors_follower_collaboratos
#
##            collaborators_follower[item] = len(followers)
#            
#            if(gh.ratelimit_remaining < 100):
#                time.sleep(60 * 60)

#
#    f_contributors_watch = open(CONTRIBUTORS_WATCH_FILE, 'w')
#    print 'Printing dictionary: watch'
#    for key, value in contributors_watch_dict.items():
#        sys.stdout.write(key + ", " + str(value) + '\n')
#        f_contributors_watch.write(key + ", " + str(value) + '\n')
#
#    f_contributors_watch.close()

except Exception as e: 
    print 'The final Exception' + str(e.args[0])

print str(gh.ratelimit_remaining) + ' request remaining'

print
print 'Finally the end'